package com.dcsgo.socketPlay.client.game;

import com.dcsgo.socketPlay.client.Services;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * @author DCSGO
 * @version 1.0
 * 游戏绘图框架
 */
public class GameFrame extends JFrame {

    public GameFrame() {
        int frameWidth = Integer.parseInt(Game.getProperty("gameFrameWidth"));
        int frameHeight = Integer.parseInt(Game.getProperty("gameFrameHeight"));
        this.setVisible(true);
        this.setSize(frameWidth, frameHeight);
        GamePanel gamePanel = new GamePanel();
        this.add(gamePanel);
        this.addKeyListener(gamePanel);
        new Thread(gamePanel).start();
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //窗口监听器 用于监听关闭中
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                Services.sendClientOffline();
            }
        });

    }
}
